home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_cyrus-sasl.idb / usr / freeware / doc / cyrus-sasl / draft-leach-digest-sasl-05.txt.z / draft-leach-digest-sasl-05.txt
Text File  |  2001-07-06  |  57KB  |  1,622 lines

  1.                          Digest SASL Mechanism          September, 1999 
  2.  
  3.  
  4.  
  5.  
  6. Network Working Group               Paul J. Leach, Microsoft 
  7. INTERNET-DRAFT                        Chris Newman, Innosoft 
  8. draft-leach-digest-sasl-05.txt 
  9. Category: Standards Track 
  10. Expires April 21, 2000                      October 21, 1999 
  11.                                      
  12.  
  13.  
  14.             Using Digest Authentication as a SASL Mechanism 
  15.  
  16.                            Author's draft: 16 
  17.  
  18.  
  19.  
  20.  
  21. STATUS OF THIS MEMO 
  22.  
  23. This document is an Internet-Draft and is in full conformance with all 
  24. provisions of Section 10 of RFC2026.  
  25.  
  26. Internet-Drafts are working documents of the Internet Engineering Task 
  27. Force (IETF), its areas, and its working groups. Note that other groups 
  28. may also distribute working documents as Internet-Drafts. 
  29.  
  30. Internet-Drafts are draft documents valid for a maximum of six months 
  31. and may be updated, replaced, or obsoleted by other documents at any 
  32. time. It is inappropriate to use Internet- Drafts as reference material 
  33. or to cite them other than as "work in progress." 
  34.  
  35. The list of current Internet-Drafts can be accessed at 
  36.     http://www.ietf.org/ietf/1id-abstracts.txt  
  37.  
  38. The list of Internet-Draft Shadow Directories can be accessed at 
  39.     http://www.ietf.org/shadow.html.  
  40.  
  41. Distribution of this document is unlimited.  Please send comments to the 
  42. authors or the SASL mailing list, ietf-sasl@imc.org. 
  43.  
  44. Copyright Notice: Copyright (C) The Internet Society (1998). All Rights 
  45. Reserved. See section 8 for the full copyright notice. 
  46.  
  47.  
  48. ABSTRACT 
  49.  
  50. This specification defines how HTTP Digest Authentication [Digest] can 
  51. be used as a SASL [RFC 2222] mechanism for any protocol that has a SASL 
  52. profile. It is intended both as an improvement over CRAM-MD5 [RFC2195] 
  53. and as a convenient way to support a single authentication mechanism for 
  54. web, mail, LDAP, and other protocols. 
  55.  
  56.  
  57.  
  58.  
  59. Leach, Newman         Standards Track              [Page 1] 
  60.  
  61.  
  62.                          Digest SASL Mechanism          September, 1999 
  63.  
  64.  
  65.  
  66.  
  67. Table of Contents 
  68.  
  69. 1 INTRODUCTION........................................................3 
  70.  1.1 CONVENTIONS AND NOTATION..........................................3 
  71.  
  72.  1.2 REQUIREMENTS......................................................4 
  73.  
  74. 2 AUTHENTICATION......................................................4 
  75.  2.1 INITIAL AUTHENTICATION............................................4 
  76.  
  77.   2.1.1 Step One......................................................4 
  78.  
  79.   2.1.2 Step Two......................................................7 
  80.  
  81.   2.1.3 Step Three...................................................12 
  82.  
  83.  2.2 SUBSEQUENT AUTHENTICATION........................................13 
  84.  
  85.   2.2.1 Step one.....................................................13 
  86.  
  87.   2.2.2 Step Two.....................................................13 
  88.  
  89.  2.3 INTEGRITY PROTECTION.............................................14 
  90.  
  91.  2.4 CONFIDENTIALITY PROTECTION.......................................14 
  92.  
  93. 3 SECURITY CONSIDERATIONS............................................15 
  94.  3.1 AUTHENTICATION OF CLIENTS USING DIGEST AUTHENTICATION............15 
  95.  
  96.  3.2 COMPARISON OF DIGEST WITH PLAINTEXT PASSWORDS....................16 
  97.  
  98.  3.3 REPLAY ATTACKS...................................................16 
  99.  
  100.  3.4 ONLINE DICTIONARY ATTACKS........................................16 
  101.  
  102.  3.5 OFFLINE DICTIONARY ATTACKS.......................................16 
  103.  
  104.  3.6 MAN IN THE MIDDLE................................................17 
  105.  
  106.  3.7 CHOSEN PLAINTEXT ATTACKS.........................................17 
  107.  
  108.  3.8 SPOOFING BY COUNTERFEIT SERVERS..................................17 
  109.  
  110.  3.9 STORING PASSWORDS................................................17 
  111.  
  112.  3.10 MULTIPLE REALMS................................................18 
  113.  
  114.  
  115.  
  116.  
  117. Leach, Newman         Standards Track              [Page 2] 
  118.  
  119.  
  120.                          Digest SASL Mechanism          September, 1999 
  121.  
  122.  
  123.  
  124.  
  125.  3.11 SUMMARY........................................................18 
  126.  
  127. 4 EXAMPLE............................................................18 
  128.  
  129. 5 REFERENCES.........................................................20 
  130.  
  131. 6 AUTHORS' ADDRESSES.................................................21 
  132.  
  133. 7 ABNF...............................................................21 
  134.  7.1 AUGMENTED BNF....................................................22 
  135.  
  136.  7.2 BASIC RULES......................................................23 
  137.  
  138. 8 SAMPLE CODE........................................................25 
  139.  
  140. 9 FULL COPYRIGHT STATEMENT...........................................26 
  141.  
  142.  
  143.  
  144. 1  Introduction 
  145.  
  146. This specification describes the use of HTTP Digest Access 
  147. Authentication as a SASL mechanism. The authentication type associated 
  148. with the Digest SASL mechanism is "DIGEST-MD5". 
  149.  
  150. This specification is intended to be upward compatible with the "md5-
  151. sess" algorithm of HTTP/1.1 Digest Access Authentication specified in 
  152. [Digest]. The only difference in the "md5-sess" algorithm is that some 
  153. directives not needed in a SASL mechanism have had their values 
  154. defaulted. 
  155.  
  156. There is one new feature for use as a SASL mechanism: integrity 
  157. protection on application protocol messages after an authentication 
  158. exchange. 
  159.  
  160. Also, compared to CRAM-MD5, DIGEST-MD5 prevents chosen plaintext 
  161. attacks, and permits the use of third party authentication servers, 
  162. mutual authentication, and optimized reauthentication if a client has 
  163. recently authenticated to a server. 
  164.  
  165. 1.1   Conventions and Notation 
  166.  
  167. This specification uses the same ABNF notation and lexical conventions 
  168. as HTTP/1.1 specification; see appendix A. 
  169.  
  170. Let { a, b, ... } be the concatenation of the octet strings a, b, ... 
  171.  
  172. Let H(s) be the 16 octet MD5 hash [RFC 1321] of the octet string s. 
  173.  
  174.  
  175.  
  176. Leach, Newman         Standards Track              [Page 3] 
  177.  
  178.  
  179.                          Digest SASL Mechanism          September, 1999 
  180.  
  181.  
  182.  
  183.  
  184. Let KD(k, s) be H({k, ":", s}), i.e., the 16 octet hash of the string k, 
  185. a colon and the string s. 
  186.  
  187. Let HEX(n) be the representation of the 16 octet MD5 hash n as a string 
  188. of 32 hex digits (with alphabetic characters always in lower case, since 
  189. MD5 is case sensitive). 
  190.  
  191. Let HMAC(k, s) be the 16 octet HMAC-MD5 [RFC 2104] of the octet string s 
  192. using the octet string k as a key. 
  193.  
  194. The value of a quoted string constant as an octet string does not 
  195. include any terminating null character. 
  196.  
  197. 1.2   Requirements  
  198.  
  199. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 
  200. "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 
  201. document are to be interpreted as described in RFC 2119 [RFC 2119].  
  202.  
  203. An implementation is not compliant if it fails to satisfy one or more of 
  204. the MUST level requirements for the protocols it implements. An 
  205. implementation that satisfies all the MUST level and all the SHOULD 
  206. level requirements for its protocols is said to be "unconditionally 
  207. compliant"; one that satisfies all the MUST level requirements but not 
  208. all the SHOULD level requirements for its protocols is said to be 
  209. "conditionally compliant." 
  210.  
  211.  
  212. 2  Authentication 
  213.  
  214. The following sections describe how to use Digest as a SASL 
  215. authentication mechanism. 
  216.  
  217. 2.1   Initial Authentication 
  218.  
  219. If the client has not recently authenticated to the server, then it must 
  220. perform "initial authentication", as defined in this section. If it has 
  221. recently authenticated, then a more efficient form is available, defined 
  222. in the next section. 
  223.  
  224. 2.1.1Step One 
  225.  
  226. The server starts by sending a challenge. The data encoded in the 
  227. challenge contains a string formatted according to the rules for a 
  228. "digest-challenge" defined as follows:  
  229.  
  230. digest-challenge  = 
  231.       1#( realm | nonce | qop-options | stale | maxbuf | charset 
  232.             algorithm | cipher-opts | auth-param ) 
  233.  
  234.  
  235.  
  236.  
  237. Leach, Newman         Standards Track              [Page 4] 
  238.  
  239.  
  240.                          Digest SASL Mechanism          September, 1999 
  241.  
  242.  
  243.  
  244.  
  245.  
  246.      realm             = "realm" "=" <"> realm-value <"> 
  247.      realm-value       = qdstr-val 
  248.      nonce             = "nonce" "=" <"> nonce-value <"> 
  249.      nonce-value       = qdstr-val 
  250.      qop-options       = "qop" "=" <"> qop-list <"> 
  251.      qop-list          = 1#qop-value 
  252.      qop-value         = "auth" | "auth-int" | "auth-conf" | 
  253.                           token 
  254.      stale             = "stale" "=" "true" 
  255.      maxbuf            = "maxbuf" "=" maxbuf-value 
  256.      maxbuf-value      = 1*DIGIT 
  257.      charset           = "charset" "=" "utf-8" 
  258.      algorithm         = "algorithm" "=" "md5-sess" 
  259.      cipher-opts       = "cipher" "=" <"> 1#cipher-value <"> 
  260.      cipher-value      = "3des" | "des" | "rc4-40" | "rc4" | 
  261.                          "rc4-56" | token 
  262.      auth-param        = token "=" ( token | quoted-string ) 
  263.  
  264. The meanings of the values of the directives used above are as follows: 
  265.  
  266. realm 
  267.   Mechanistically, a string which can enable users to know which 
  268.   username and password to use, in case they might have different ones 
  269.   for different servers. Conceptually, it is the name of a collection 
  270.   of accounts that might include the user's account. This string should 
  271.   contain at least the name of the host performing the authentication 
  272.   and might additionally indicate the collection of users who might 
  273.   have access. An example might be 
  274.   "registered_users@gotham.news.example.com".  This directive is 
  275.   optional; if not present, the client SHOULD solicit it from the user 
  276.   or be able to compute a default; a plausible default might be the 
  277.   realm supplied by the user when they logged in to the client system. 
  278.   Multiple realm directives are allowed, in which case the user or 
  279.   client must choose one as the realm for which to supply to username 
  280.   and password. 
  281.  
  282. nonce 
  283.   A server-specified data string which MUST be different each time a 
  284.   digest-challenge is sent as part of initial authentication.  It is 
  285.   recommended that this string be base64 or hexadecimal data. Note that 
  286.   since the string is passed as a quoted string, the double-quote 
  287.   character is not allowed unless escaped (see section 7.2). The 
  288.   contents of the nonce are implementation dependent. The security of 
  289.   the implementation depends on a good choice. It is RECOMMENDED that 
  290.   it contain at least 64 bits of entropy. The nonce is opaque to the 
  291.   client. This directive is required and MUST appear exactly once; if 
  292.   not present, or if multiple instances are present, the client should 
  293.   abort the authentication exchange.  
  294.  
  295.  
  296.  
  297. Leach, Newman         Standards Track              [Page 5] 
  298.  
  299.  
  300.                          Digest SASL Mechanism          September, 1999 
  301.  
  302.  
  303.  
  304.  
  305. qop-options 
  306.   A quoted string of one or more tokens indicating the "quality of 
  307.   protection" values supported by the server.  The value "auth" 
  308.   indicates authentication; the value "auth-int" indicates 
  309.   authentication with integrity protection; the value "auth-conf" 
  310.   indicates authentication with integrity protection and encryption. 
  311.   This directive is optional; if not present it defaults to "auth". The 
  312.   client MUST ignore unrecognized options; if the client recognizes no 
  313.   option, it should abort the authentication exchange. 
  314.  
  315. stale 
  316.   The "stale" directive is not used in initial authentication. See the 
  317.   next section for its use in subsequent authentications. This 
  318.   directive may appear at most once; if multiple instances are present, 
  319.   the client should abort the authentication exchange. 
  320.  
  321. maxbuf 
  322.   A number indicating the size of the largest buffer the server is able 
  323.   to receive when using "auth-int" or "auth-conf". If this directive is 
  324.   missing, the default value is 65536. This directive may appear at 
  325.   most once; if multiple instances are present, the client should abort 
  326.   the authentication exchange. 
  327.  
  328. charset 
  329.   This directive, if present, specifies that the server supports UTF-8 
  330.   encoding for the username and password. If not present, the username 
  331.   and password must be encoded in ISO 8859-1 (of which US-ASCII is a 
  332.   subset). The directive is needed for backwards compatibility with 
  333.   HTTP Digest, which only supports ISO 8859-1. This directive may 
  334.   appear at most once; if multiple instances are present, the client 
  335.   should abort the authentication exchange. 
  336.  
  337. algorithm 
  338.   This directive is required for backwards compatibility with HTTP 
  339.   Digest., which supports other algorithms. . This directive is 
  340.   required and MUST appear exactly once; if not present, or if multiple 
  341.   instances are present, the client should abort the authentication 
  342.   exchange. 
  343.  
  344. cipher-opts 
  345.   A list of ciphers that the server supports. This directive must be 
  346.   present exactly once if "auth-conf" is offered in the "qop-options" 
  347.   directive, in which case the "3des" and "des" modes are mandatory-to-
  348.   implement. The client MUST ignore unrecognized options; if the client 
  349.   recognizes no option, it should abort the authentication exchange. 
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356. Leach, Newman         Standards Track              [Page 6] 
  357.  
  358.  
  359.                          Digest SASL Mechanism          September, 1999 
  360.  
  361.  
  362.  
  363.  
  364.   des 
  365.      the Data Encryption Standard (DES) cipher [FIPS] in cipher block 
  366.      chaining (CBC) mode with a 56 bit key. 
  367.  
  368.   3des 
  369.      the "triple DES" cipher in CBC mode with EDE with the same key for 
  370.      each E stage (aka "two keys mode") for a total key length of 112 
  371.      bits. 
  372.  
  373.   rc4, rc4-40, rc4-56 
  374.      the RC4 cipher with a 128 bit, 40 bit, and 56 bit key, 
  375.      respectively. 
  376.  
  377. auth-param 
  378.   This construct allows for future extensions; it may appear more than 
  379.   once. The client MUST ignore any unrecognized directives. 
  380.  
  381. For use as a SASL mechanism, note that the following changes are made to 
  382. "digest-challenge" from HTTP: the following Digest options (called 
  383. "directives" in HTTP terminology) are unused (i.e., MUST NOT be sent, 
  384. and MUST be ignored if received): 
  385.  
  386.     opaque 
  387.     domain 
  388.      
  389. The size of a digest-challenge MUST be less than 2048 bytes. 
  390.  
  391. 2.1.2Step Two 
  392.  
  393. The client makes note of the "digest-challenge" and then responds with a 
  394. string formatted and computed according to the rules for a "digest-
  395. response" defined as follows: 
  396.  
  397. digest-response  = 1#( username | realm | nonce | cnonce | 
  398.                        nonce-count | qop | digest-uri | response | 
  399.                        maxbuf | charset | cipher | authzid | 
  400.                        auth-param ) 
  401.  
  402.     username         = "username" "=" <"> username-value <"> 
  403.     username-value   = qdstr-val 
  404.     cnonce           = "cnonce" "=" <"> cnonce-value <"> 
  405.     cnonce-value     = qdstr-val 
  406.     nonce-count      = "nc" "=" nc-value 
  407.     nc-value         = 8LHEX 
  408.     qop              = "qop" "=" qop-value 
  409.     digest-uri       = "digest-uri" "=" <"> digest-uri-value <"> 
  410.     digest-uri-value  = serv-type "/" host [ "/" serv-name ] 
  411.     serv-type        = 1*ALPHA 
  412.     host             = 1*( ALPHA | DIGIT | "-" | "." ) 
  413.  
  414.  
  415.  
  416. Leach, Newman         Standards Track              [Page 7] 
  417.  
  418.  
  419.                          Digest SASL Mechanism          September, 1999 
  420.  
  421.  
  422.  
  423.  
  424.     serv-name        = host 
  425.     response         = "response" "=" response-value 
  426.     response-value   = 32LHEX 
  427.     LHEX             = "0" | "1" | "2" | "3" | 
  428.                        "4" | "5" | "6" | "7" | 
  429.                        "8" | "9" | "a" | "b" | 
  430.                        "c" | "d" | "e" | "f" 
  431.     cipher           = "cipher" "=" cipher-value 
  432.     authzid          = "authzid" "=" <"> authzid-value <"> 
  433.     authzid-value    = qdstr-val 
  434.  
  435.  
  436.  
  437. username 
  438.   The user's name in the specified realm, encoded according to the 
  439.   value of the "charset" directive. This directive is required and MUST 
  440.   be present exactly once; otherwise, authentication fails. 
  441.  
  442. realm 
  443.   The realm containing the user's account. This directive is required 
  444.   if the server provided any realms in the "digest-challenge", in which 
  445.   case it may appear exactly once and its value SHOULD be one of those 
  446.   realms. If the directive is missing, "realm-value" will set to the 
  447.   empty string when computing A1 (see below for details). 
  448.  
  449. nonce 
  450.   The server-specified data string received in the preceding digest-
  451.   challenge. This directive is required and MUST be present exactly 
  452.   once; otherwise, authentication fails. 
  453.  
  454. cnonce 
  455.   A client-specified data string which MUST be different each time a 
  456.   digest-response is sent as part of initial authentication. The 
  457.   cnonce-value is an opaque quoted string value provided by the client 
  458.   and used by both client and server to avoid chosen plaintext attacks, 
  459.   and to provide mutual authentication. The security of the 
  460.   implementation depends on a good choice. It is RECOMMENDED that it 
  461.   contain at least 64 bits of entropy. This directive is required and 
  462.   MUST be present exactly once; otherwise, authentication fails. 
  463.  
  464. nonce-count 
  465.   The nc-value is the hexadecimal count of the number of requests 
  466.   (including the current request) that the client has sent with the 
  467.   nonce value in this request.  For example, in the first request sent 
  468.   in response to a given nonce value, the client sends "nc=00000001".  
  469.   The purpose of this directive is to allow the server to detect 
  470.   request replays by maintaining its own copy of this count - if the 
  471.   same nc-value is seen twice, then the request is a replay.   See the 
  472.  
  473.  
  474.  
  475. Leach, Newman         Standards Track              [Page 8] 
  476.  
  477.  
  478.                          Digest SASL Mechanism          September, 1999 
  479.  
  480.  
  481.  
  482.  
  483.   description below of the construction of the response value. This 
  484.   directive may appear at most once; if multiple instances are present, 
  485.   the client should abort the authentication exchange. 
  486.  
  487. qop 
  488.   Indicates what "quality of protection" the client accepted. If 
  489.   present, it may appear exactly once and  its value MUST be one of the 
  490.   alternatives in qop-options. If not present, it defaults to "auth". 
  491.   These values affect the computation of the response. Note that this 
  492.   is a single token, not a quoted list of alternatives. 
  493.  
  494. serv-type 
  495.   Indicates the type of service, such as "www" for web service, "ftp" 
  496.   for FTP service, "smtp" for mail delivery service, etc. The service 
  497.   name as defined in the SASL profile for the protocol see section 4 of 
  498.   [RFC 2222], registered in the IANA registry of "service" elements for 
  499.   the GSSAPI host-based service name form [RFC 2078].  Regardless of 
  500.   case, they are lower cased when used in hash computations. 
  501.  
  502. host 
  503.   The DNS host name or IP address for the service requested.  The DNS 
  504.   host name must be the fully-qualified canonical name of the host.  
  505.   The DNS host name is the preferred form; see notes on server 
  506.   processing of the digest-uri. 
  507.  
  508. serv-name 
  509.   Indicates the name of the service if it is replicated. The service is 
  510.   considered to be replicated if the client's service-location process 
  511.   involves resolution using standard DNS lookup operations, and if 
  512.   these operations involve DNS records (such as SRV, or MX) which 
  513.   resolve one DNS name into a set of other DNS names. In this case, the 
  514.   initial name used by the client is the "serv-name", and the final 
  515.   name is the "host" component. For example, the incoming mail service 
  516.   for "example.com" may be replicated through the use of MX records 
  517.   stored in the DNS, one of which points at an SMTP server called 
  518.   "mail3.example.com"; it's "serv-name" would be "example.com", it's 
  519.   "host" would be "mail3.example.com". If the service is not 
  520.   replicated, or the serv-name is identical to the host, then the serv-
  521.   name component MUST be omitted. 
  522.  
  523. digest-uri 
  524.   Indicates the principal name of the service with which the client 
  525.   wishes to connect, formed from the serv-type, host, and serv-name. 
  526.   For example, the FTP service on "ftp.example.com" would have a 
  527.   "digest-uri" value of "ftp/ftp.example.com"; the SMTP server from the 
  528.   example above would have a "digest-uri" value of 
  529.   "smtp/mail3.example.com/example.com". 
  530.  
  531.  
  532.  
  533.  
  534. Leach, Newman         Standards Track              [Page 9] 
  535.  
  536.  
  537.                          Digest SASL Mechanism          September, 1999 
  538.  
  539.  
  540.  
  541.  
  542.    Servers SHOULD check that the supplied value is correct. This will 
  543.   detect accidental connection to the incorrect server. It is also so 
  544.   that clients will be trained to provide values that will work with 
  545.   implementations that use a shared back-end authentication service 
  546.   that can provide server authentication. 
  547.  
  548.   The serv-type component should match the service being offered. The 
  549.   host component should match one of the host names of the host on 
  550.   which the service is running, or it's IP address. Servers SHOULD NOT 
  551.   normally support the IP address form, because server authentication 
  552.   by IP address is not very useful; they should only do so if the DNS 
  553.   is unavailable or unreliable. The serv-name component should match 
  554.   one of the service's configured service names.  
  555.  
  556.   This directive may appear at most once; if multiple instances are 
  557.   present, the client should abort the authentication exchange. 
  558.  
  559.   Note: In the HTTP use of Digest authentication, the digest-uri is the 
  560.   URI (usually a URL) of the resource requested -- hence the name of 
  561.   the directive. 
  562.  
  563. response  
  564.   A string of 32 hex digits computed as defined below, which proves 
  565.   that the user knows a password. This directive is required and MUST 
  566.   be present exactly once; otherwise, authentication fails. 
  567.  
  568. maxbuf 
  569.   A number indicating the size of the largest buffer the client is able 
  570.   to receive. If this directive is missing, the default value is 65536. 
  571.   This directive may appear at most once; if multiple instances are 
  572.   present, the server should abort the authentication exchange. 
  573.  
  574. charset 
  575.   This directive, if present, specifies that the client has used UTF-8 
  576.   encoding for the username and password. If not present, the username 
  577.   and password must be encoded in ISO 8859-1 (of which US-ASCII is a 
  578.   subset). The client should send this directive only if the server has 
  579.   indicated it supports UTF-8. The directive is needed for backwards 
  580.   compatibility with HTTP Digest, which only supports ISO 8859-1. 
  581.  
  582. LHEX 
  583.   32 hex digits, where the alphabetic characters MUST be lower case, 
  584.   because MD5 is not case insensitive. 
  585.  
  586. cipher 
  587.   The cipher chosen by the client. This directive MUST appear exactly 
  588.   once if "auth-conf" is negotiated; if required and not present, 
  589.   authentication fails. 
  590.  
  591.  
  592.  
  593. Leach, Newman         Standards Track             [Page 10] 
  594.  
  595.  
  596.                          Digest SASL Mechanism          September, 1999 
  597.  
  598.  
  599.  
  600.  
  601. authzid 
  602.   The "authorization ID" as per RFC 2222, encoded in UTF-8. This 
  603.   directive is optional. If present, and the authenticating user has 
  604.   sufficient privilege, and the server supports it, then after 
  605.   authentication the server will use this identity for making all 
  606.   accesses and access checks. If the client specifies it, and the 
  607.   server does not support it, then the response-value will be 
  608.   incorrect, and authentication will fail. 
  609.  
  610. The size of a digest-response MUST be less than 4096 bytes. 
  611.  
  612.  
  613. 2.1.2.1   Response-value 
  614. The definition of "response-value" above indicates the encoding for its 
  615. value -- 32 lower case hex characters. The following definitions show 
  616. how the value is computed. 
  617.  
  618.    response-value  =  
  619.       HEX( KD ( HEX(H(A1)), 
  620.               { nonce-value, ":" nc-value, ":",  
  621.                 cnonce-value, ":", qop-value, ":", HEX(H(A2)) })) 
  622.   
  623. If authzid is specified, then A1 is 
  624.  
  625.  
  626.    A1 = { H( { username-value, ":", realm-value, ":", passwd } ),  
  627.         ":", nonce-value, ":", cnonce-value, ":", authzid-value } 
  628.  
  629. If authzid is not specified, then A1 is 
  630.  
  631.  
  632.    A1 = { H( { username-value, ":", realm-value, ":", passwd } ),  
  633.         ":", nonce-value, ":", cnonce-value } 
  634.  
  635. where 
  636.  
  637.       passwd   = *OCTET 
  638.  
  639. The "username-value", "realm-value" and "passwd" are encoded according 
  640. to the value of the "charset" directive. If "charset=UTF-8" is present, 
  641. and all the characters of either "username-value" or "passwd" are in the 
  642. ISO 8859-1 character set, then it must be converted to ISO 8859-1 before 
  643. being hashed. This is so that authentication databases that store the 
  644. hashed username, realm and password (which is common) can be shared 
  645. compatibly with HTTP, which specifies ISO 8859-1. A sample 
  646. implementation of this conversion is in section 8. 
  647.  
  648. If the "qop" directive's value is "auth", then A2 is: 
  649.  
  650.  
  651.  
  652.  
  653. Leach, Newman         Standards Track             [Page 11] 
  654.  
  655.  
  656.                          Digest SASL Mechanism          September, 1999 
  657.  
  658.  
  659.  
  660.  
  661.    A2       = { "AUTHENTICATE:", digest-uri-value } 
  662.  
  663. If the "qop" value is "auth-int" or "auth-conf" then A2 is: 
  664.  
  665.    A2       = { "AUTHENTICATE:", digest-uri-value,  
  666.             ":00000000000000000000000000000000" } 
  667.  
  668. Note that "AUTHENTICATE:" must be in upper case, and the second string 
  669. constant is a string with a colon followed by 32 zeros. 
  670.  
  671. These apparently strange values of A2 are for compatibility with HTTP; 
  672. they were arrived at by setting "Method" to "AUTHENTICATE" and the hash 
  673. of the entity body to zero in the HTTP digest calculation of A2. 
  674.  
  675. Also, in the HTTP usage of Digest, several directives in the "digest-
  676. challenge" sent by the server have to be returned by the client in the 
  677. "digest-response". These are: 
  678.  
  679.     opaque 
  680.     algorithm 
  681.      
  682. These directives are not needed when Digest is used as a SASL mechanism 
  683. (i.e., MUST NOT be sent, and MUST be ignored if received). 
  684.  
  685. 2.1.3Step Three 
  686.  
  687. The server receives and validates the "digest-response". The server 
  688. checks that the nonce-count is "00000001". If it supports subsequent 
  689. authentication (see section 2.2), it saves the value of the nonce and 
  690. the nonce-count. It sends a message formatted as follows: 
  691.  
  692.     response-auth = "rspauth" "=" response-value 
  693.      
  694. where response-value is calculated as above, using the values sent in 
  695. step two, except that if qop is "auth", then A2 is 
  696.  
  697.     A2 = { ":", digest-uri-value } 
  698.      
  699. And if qop is "auth-int" or "auth-conf" then A2 is 
  700.  
  701.     A2 = { ":", digest-uri-value, ":00000000000000000000000000000000" } 
  702.      
  703. Compared to its use in HTTP, the following Digest directives in the 
  704. "digest-response" are unused: 
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. Leach, Newman         Standards Track             [Page 12] 
  715.  
  716.  
  717.                          Digest SASL Mechanism          September, 1999 
  718.  
  719.  
  720.  
  721.  
  722.     nextnonce 
  723.     qop 
  724.     cnonce 
  725.     nonce-count 
  726.      
  727. 2.2   Subsequent Authentication 
  728.  
  729. If the client has previously authenticated to the server, and remembers 
  730. the values of username, realm, nonce, nonce-count, cnonce, and qop that 
  731. it used in that authentication, and the SASL profile for a protocol 
  732. permits an initial client response, then it MAY perform "subsequent 
  733. authentication", as defined in this section. 
  734.  
  735. 2.2.1Step one 
  736.  
  737. The client uses the values from the previous authentication and sends an 
  738. initial response with a string formatted and computed according to the 
  739. rules for a "digest-response", as defined above, but with a nonce-count 
  740. one greater than used in the last "digest-response". 
  741.  
  742. 2.2.2Step Two 
  743.  
  744. The server receives the "digest-response". If the server does not 
  745. support subsequent authentication, then it sends a "digest-challenge", 
  746. and authentication proceeds as in initial authentication. If the server 
  747. has no saved nonce and nonce-count from a previous authentication, then 
  748. it sends a "digest-challenge", and authentication proceeds as in initial 
  749. authentication. Otherwise, the server validates the "digest-response", 
  750. checks that the nonce-count is one greater than that used in the 
  751. previous authentication using that nonce, and saves the new value of 
  752. nonce-count. 
  753.  
  754. If the response is invalid, then the server sends a "digest-challenge", 
  755. and authentication proceeds as in initial authentication  (and should be 
  756. configurable to log an authentication failure in some sort of security 
  757. audit log, since the failure may be a symptom of an attack). The nonce-
  758. count MUST NOT be incremented in this case: to do so would allow a 
  759. denial of service attack by sending an out-of-order nonce-count. 
  760.  
  761. If the response is valid, the server MAY choose to deem that 
  762. authentication has succeeded. However, if it has been too long since the 
  763. previous authentication, or for any other reason, the server MAY send a 
  764. new "digest-challenge" with a new value for nonce. The challenge MAY 
  765. contain a "stale" directive with value "true", which says that the 
  766. client may respond to the challenge using the password it used in the 
  767. previous response; otherwise, the client must solicit the password anew 
  768. from the user. This permits the server to make sure that the user has 
  769. presented their password recently. (The directive name refers to the 
  770. previous nonce being stale, not to the last use of the password.) Except 
  771.  
  772.  
  773.  
  774.  
  775. Leach, Newman         Standards Track             [Page 13] 
  776.  
  777.  
  778.                          Digest SASL Mechanism          September, 1999 
  779.  
  780.  
  781.  
  782.  
  783. for the handling of "stale", after sending the "digest-challenge" 
  784. authentication proceeds as in the case of initial authentication. 
  785.  
  786. 2.3   Integrity Protection 
  787.  
  788. If the server offered "qop=auth-int" and the client responded "qop=auth-
  789. int", then subsequent messages, up to but not including the next 
  790. subsequent authentication, between the client and the server MUST be 
  791. integrity protected. Using as a base session key the value of H(A1) as 
  792. defined above the client and server calculate a pair of message 
  793. integrity keys as follows. 
  794.  
  795. The key for integrity protecting messages from client to server is: 
  796.  
  797. Kic = MD5({H(A1), 
  798. "Digest session key to client-to-server signing key magic constant"}) 
  799.  
  800. The key for integrity protecting messages from server to client is: 
  801.  
  802. Kis = MD5({H(A1), 
  803. "Digest session key to server-to-client signing key magic constant"}) 
  804.  
  805. where MD5 is as specified in [RFC 1321]. If message integrity is 
  806. negotiated, a MAC block for each message is appended to the message. The 
  807. MAC block is 16 bytes: the first 10 bytes of the HMAC-MD5 [RFC 2104] of 
  808. the message, a 2-byte message type number in network byte order with 
  809. value 1, and the 4-byte sequence number in network byte order. The 
  810. message type is to allow for future extensions such as rekeying. 
  811.  
  812. MAC(Ki, SeqNum, msg) = (HMAC(Ki, {SeqNum, msg})[0..9], 0x0001, SeqNum) 
  813.  
  814. where Ki is Kic for messages sent by the client and Kis for those sent 
  815. by the server. The sequence number is initialized to zero, and 
  816. incremented by one for each message sent. 
  817.  
  818. Upon receipt, MAC(Ki, SeqNum, msg) is computed and compared with the 
  819. received value; the message is discarded if they differ. 
  820.  
  821. 2.4   Confidentiality Protection 
  822.  
  823. If the server sent a "cipher-opts" directive and the client responded 
  824. with a "cipher" directive, then subsequent messages between the client 
  825. and the server MUST be confidentiality protected. Using as a base 
  826. session key the value of H(A1) as defined above the client and server 
  827. calculate a pair of message integrity keys as follows. 
  828.  
  829. The key for confidentiality protecting messages from client to server 
  830. is: 
  831.  
  832. Kcc = MD5({H(A1)[0..n], 
  833.  
  834.  
  835.  
  836. Leach, Newman         Standards Track             [Page 14] 
  837.  
  838.  
  839.                          Digest SASL Mechanism          September, 1999 
  840.  
  841.  
  842.  
  843.  
  844. "Digest H(A1) to client-to-server sealing key magic constant"}) 
  845.  
  846. The key for confidentiality protecting messages from server to client 
  847. is: 
  848.  
  849. Kcs = MD5({H(A1)[0..n], 
  850. "Digest H(A1) to server-to-client sealing key magic constant"}) 
  851.  
  852. where MD5 is as specified in [RFC 1321]. For cipher "rc4-40" n is 5; for 
  853. "rc4-56" n is 7; for the rest n is 16. The key for the "rc-*" ciphers is 
  854. all 16 bytes of Kcc or Kcs; the key for "des" is the first 7 bytes; the 
  855. key for "3des" is the first 14 bytes. The IV for "des" and "3des" is the 
  856. last 8 bytes of Kcc or Kcs. 
  857.  
  858. If message confidentiality is negotiated, each message is encrypted with 
  859. the chosen cipher and a MAC block is appended to the message. 
  860.  
  861. The MAC block is a variable length padding prefix followed by 16 bytes 
  862. formatted as follows: the first 10 bytes of the HMAC-MD5 [RFC 2104] of 
  863. the message, a 2-byte message type number in network byte order with 
  864. value 1, and the 4-byte sequence number in network byte order. If the 
  865. blocksize of the chosen cipher is not 1 byte, the padding prefix is one 
  866. or more octets each containing the number of padding bytes, such that 
  867. total length of the encrypted part of the message is a multiple of the 
  868. blocksize. The padding and first 10 bytes of the MAC block are encrypted 
  869. along with the message. 
  870.  
  871. SEAL(Ki, Kc, SeqNum, msg) =  
  872.       {CIPHER(Kc, {msg, pad, HMAC(Ki, {SeqNum, msg})[0..9])}), 0x0001, 
  873.        SeqNum} 
  874.  
  875. where CIPHER is the chosen cipher, Ki and Kc are Kic and Kcc for 
  876. messages sent by the client and Kis and Kcs for those sent by the 
  877. server. The sequence number is initialized to zero, and incremented by 
  878. one for each message sent. 
  879.  
  880. Upon receipt, the message is decrypted, HMAC(Ki, {SeqNum, msg}) is 
  881. computed and compared with the received value; the message is discarded 
  882. if they differ. 
  883.  
  884.  
  885. 3  Security Considerations 
  886.  
  887. 3.1   Authentication of Clients using Digest Authentication 
  888.  
  889. Digest Authentication does not provide a strong authentication 
  890. mechanism, when compared to public key based mechanisms, for example. 
  891. However, since it prevents chosen plaintext attacks, it is stronger than 
  892. (e.g.) CRAM-MD5, which has been proposed for use with LDAP [10], POP and 
  893. IMAP (see RFC 2195 [9]).   It is intended to replace the much weaker and 
  894.  
  895.  
  896.  
  897. Leach, Newman         Standards Track             [Page 15] 
  898.  
  899.  
  900.                          Digest SASL Mechanism          September, 1999 
  901.  
  902.  
  903.  
  904.  
  905. even more dangerous use of plaintext passwords; however, since it is 
  906. still a password based mechanism it avoids some of the potential 
  907. deployabilty issues with public-key, OTP or similar mechanisms. 
  908.  
  909. Digest Authentication offers no confidentiality protection beyond 
  910. protecting the actual password. All of the rest of the challenge 
  911. and response are available to an eavesdropper, including the 
  912. user's name and authentication realm. 
  913.  
  914. 3.2   Comparison of Digest with Plaintext Passwords 
  915.  
  916. The greatest threat to the type of transactions for which these 
  917. protocols are used is network snooping. This kind of transaction 
  918. might involve, for example, online access to a mail service whose 
  919. use is restricted to paying subscribers. With plaintext password 
  920. authentication an eavesdropper can obtain the password of the 
  921. user. This not only permits him to access anything in the 
  922. database, but, often worse, will permit access to anything else 
  923. the user protects with the same password. 
  924.  
  925. 3.3   Replay Attacks 
  926.  
  927. Replay attacks are defeated if the client or the server chooses a 
  928. fresh nonce for each authentication, as this specification 
  929. requires. 
  930.  
  931. 3.4   Online dictionary attacks 
  932.  
  933. If the attacker can eavesdrop, then it can test any overheard 
  934. nonce/response pairs against a (potentially very large) list of common 
  935. words. Such a list is usually much smaller than the total number of 
  936. possible passwords. The cost of computing the response for each password 
  937. on the list is paid once for each challenge. 
  938.  
  939. The server can mitigate this attack by not allowing users to select 
  940. passwords that are in a dictionary. 
  941.  
  942. 3.5   Offline dictionary attacks 
  943.  
  944. If the attacker can choose the challenge, then it can precompute the 
  945. possible responses to that challenge for a list of common words. Such a 
  946. list is usually much smaller than the total number of possible 
  947. passwords. The cost of computing the response for each password on the 
  948. list is paid just once. 
  949.  
  950. Offline dictionary attacks are defeated if the client chooses a fresh 
  951. nonce for each authentication, as this specification requires. 
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958. Leach, Newman         Standards Track             [Page 16] 
  959.  
  960.  
  961.                          Digest SASL Mechanism          September, 1999 
  962.  
  963.  
  964.  
  965.  
  966. 3.6   Man in the Middle 
  967.  
  968. Digest authentication is vulnerable to "man in the middle" (MITM) 
  969. attacks. Clearly, a MITM would present all the problems of 
  970. eavesdropping. But it also offers some additional opportunities to the 
  971. attacker. 
  972.  
  973. A possible man-in-the-middle attack would be to substitute a weaker qop 
  974. scheme for the one(s) sent by the server; the server will not be able to 
  975. detect this attack. For this reason, the client should always use the 
  976. strongest scheme that it understands from the choices offered, and 
  977. should never choose a scheme that does not meet its minimum 
  978. requirements. 
  979.  
  980. 3.7   Chosen plaintext attacks 
  981.  
  982. A chosen plaintext attack is where a MITM or a malicious server can 
  983. arbitrarily choose the challenge that the client will use to compute the 
  984. response. The ability to choose the challenge is known to make 
  985. cryptanalysis much easier [8]. 
  986.  
  987. However, Digest does not permit the attack to choose the challenge as 
  988. long as the client chooses a fresh nonce for each authentication, as 
  989. this specification requires. 
  990.  
  991. 3.8   Spoofing by Counterfeit Servers 
  992.  
  993. If a user can be led to believe that she is connecting to a host 
  994. containing information protected by a password she knows, when in fact 
  995. she is connecting to a hostile server, then the hostile server can 
  996. obtain challenge/response pairs where it was able to partly choose the 
  997. challenge. There is no known way that this can be exploited. 
  998.  
  999. 3.9   Storing passwords 
  1000.  
  1001. Digest authentication requires that the authenticating agent (usually 
  1002. the server) store some data derived from the user's name and password in 
  1003. a "password file" associated with a given realm. Normally this might 
  1004. contain pairs consisting of username and H({ username-value, ":", realm-
  1005. value, ":", passwd }), which is adequate to compute H(A1) as described 
  1006. above without directly exposing the user's password. 
  1007.  
  1008. The security implications of this are that if this password file is 
  1009. compromised, then an attacker gains immediate access to documents on the 
  1010. server using this realm. Unlike, say a standard UNIX password file, this 
  1011. information need not be decrypted in order to access documents in the 
  1012. server realm associated with this file. On the other hand, decryption, 
  1013. or more likely a brute force attack, would be necessary to obtain the 
  1014. user's password. This is the reason that the realm is part of the 
  1015. digested data stored in the password file. It means that if one Digest 
  1016.  
  1017.  
  1018.  
  1019. Leach, Newman         Standards Track             [Page 17] 
  1020.  
  1021.  
  1022.                          Digest SASL Mechanism          September, 1999 
  1023.  
  1024.  
  1025.  
  1026.  
  1027. authentication password file is compromised, it does not automatically 
  1028. compromise others with the same username and password (though it does 
  1029. expose them to brute force attack). 
  1030.  
  1031. There are two important security consequences of this. First the 
  1032. password file must be protected as if it contained plaintext passwords, 
  1033. because for the purpose of accessing documents in its realm, it 
  1034. effectively does. 
  1035.  
  1036. A second consequence of this is that the realm string should be unique 
  1037. among all realms that any single user is likely to use. In particular a 
  1038. realm string should include the name of the host doing the 
  1039. authentication.  
  1040.  
  1041. 3.10  Multiple realms 
  1042.  
  1043. Use of multiple realms may mean both that compromise of a the security 
  1044. database for a single realm does not compromise all security, and that 
  1045. there are more things to protect in order to keep the whole system 
  1046. secure. 
  1047.  
  1048. 3.11  Summary 
  1049.  
  1050. By modern cryptographic standards Digest Authentication is weak, 
  1051. compared to (say) public key based mechanisms. But for a large range of 
  1052. purposes it is valuable as a replacement for plaintext passwords. Its 
  1053. strength may vary depending on the implementation. 
  1054.  
  1055.  
  1056. 4  Example 
  1057.  
  1058. This example shows the use of the Digest SASL mechanism with the IMAP4 
  1059. AUTHENTICATE command [RFC 2060]. 
  1060.  
  1061. In this example, "C:" and "S:" represent a line sent by the client or 
  1062. server respectively including a CRLF at the end.  Linebreaks and 
  1063. indentation within a "C:" or "S:" are editorial and not part of the 
  1064. protocol. The password in this example was "secret".  Note that the 
  1065. base64 encoding of the challenges and responses is part of the IMAP4 
  1066. AUTHENTICATE command, not part of the Digest specification itself. 
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080. Leach, Newman         Standards Track             [Page 18] 
  1081.  
  1082.  
  1083.                          Digest SASL Mechanism          September, 1999 
  1084.  
  1085.  
  1086.  
  1087.  
  1088.     S: * OK elwood.innosoft.com PMDF IMAP4rev1 V6.0-9 
  1089.     C: c CAPABILITY 
  1090.     S: * CAPABILITY IMAP4 IMAP4rev1 ACL LITERAL+ NAMESPACE QUOTA 
  1091.                 UIDPLUS AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=PLAIN 
  1092.     S: c OK Completed 
  1093.     C: a AUTHENTICATE DIGEST-MD5 
  1094.     S: + cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0 
  1095.          RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh 
  1096.          cnNldD11dGYtOA== 
  1097.     C: Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2 
  1098.        QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw 
  1099.        MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im 
  1100.        ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw 
  1101.        ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg= 
  1102.     S: + cnNwYXV0aD00YjJiYjM3ZjA0OTEwNTA1Nzc3YzJmNjM4YzkyMjcyNQ== 
  1103.     C: 
  1104.     S: a OK User logged in 
  1105.     --- 
  1106.      
  1107.     The base64-decoded version of the SASL exchange is: 
  1108.      
  1109.     S: realm="elwood.innosoft.com",nonce="OA6MG9tEQGm2hh",qop="auth", 
  1110.        algorithm=md5-sess,charset=utf-8 
  1111.     C: charset=utf-8,username="chris",realm="elwood.innosoft.com", 
  1112.        nonce="OA6MG9tEQGm2hh",nc=00000001,cnonce="OA6MHXh6VqTrRk", 
  1113.        digest-uri="imap/elwood.innosoft.com", 
  1114.        response=d388dad90d4bbd760a152321f2143af7,qop=auth 
  1115.     S: rspauth=4b2bb37f04910505777c2f638c922725 
  1116.      
  1117.     The password in this example was "secret". 
  1118.      
  1119. This example shows the use of the Digest SASL mechanism with the ACAP, 
  1120. using the same notational conventions and password as in the previous 
  1121. example. Note that ACAP does not base64 encode and uses fewer round 
  1122. trips that IMAP4. 
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141. Leach, Newman         Standards Track             [Page 19] 
  1142.  
  1143.  
  1144.                          Digest SASL Mechanism          September, 1999 
  1145.  
  1146.  
  1147.  
  1148.  
  1149.     S: * ACAP (IMPLEMENTATION "Test ACAP server") (SASL "CRAM-MD5" 
  1150.                "DIGEST-MD5" "PLAIN") 
  1151.     C: a AUTHENTICATE "DIGEST-MD5" 
  1152.     S: + {94} 
  1153.     S: realm="elwood.innosoft.com",nonce="OA9BSXrbuRhWay",qop="auth", 
  1154.        algorithm=md5-sess,charset=utf-8 
  1155.     C: {206} 
  1156.     C: charset=utf-8,username="chris",realm="elwood.innosoft.com", 
  1157.        nonce="OA9BSXrbuRhWay",nc=00000001,cnonce="OA9BSuZWMSpW8m", 
  1158.        digest-uri="acap/elwood.innosoft.com", 
  1159.        response=6084c6db3fede7352c551284490fd0fc,qop=auth 
  1160.     S: a OK (SASL {40} 
  1161.     S: rspauth=d84489141f9d86605c6a77b95cb5365a) "AUTHENTICATE 
  1162.     Completed" 
  1163.     --- 
  1164.  
  1165. The server uses the values of all the directives, plus knowledge of the 
  1166. users password (or the hash of the user's name, server's realm and the 
  1167. user's password) to verify the computations above. If they check, then 
  1168. the user has authenticated. 
  1169.  
  1170.  
  1171. 5   References 
  1172.  
  1173. [Digest] Franks, J., et. al., "HTTP Authentication: Basic and Digest 
  1174.   Access Authentication", <draft-ietf-http-authentication-03>, Work in 
  1175.   Progress of the HTTP Working Group, August, 1998 
  1176.  
  1177. [ISO-8859] ISO-8859. International Standard -- Information Processing -- 
  1178.   8-bit Single-Byte Coded Graphic Character Sets -- 
  1179.   Part 1: Latin alphabet No. 1, ISO-8859-1:1987. 
  1180.   Part 2: Latin alphabet No. 2, ISO-8859-2, 1987. 
  1181.   Part 3: Latin alphabet No. 3, ISO-8859-3, 1988. 
  1182.   Part 4: Latin alphabet No. 4, ISO-8859-4, 1988. 
  1183.   Part 5: Latin/Cyrillic alphabet, ISO-8859-5, 1988. 
  1184.   Part 6: Latin/Arabic alphabet, ISO-8859-6, 1987. 
  1185.   Part 7: Latin/Greek alphabet, ISO-8859-7, 1987. 
  1186.   Part 8: Latin/Hebrew alphabet, ISO-8859-8, 1988. 
  1187.   Part 9: Latin alphabet No. 5, ISO-8859-9, 1990.  
  1188.  
  1189.  [RFC 822] D. H. Crocker, "Standard for The Format of ARPA Internet Text 
  1190.   Messages," STD 11, RFC 822, UDEL, August 1982.  
  1191.  
  1192. [RFC 1321] R. Rivest, "The MD5 Message-Digest Algorithm", RFC 1321, 
  1193.   April 1992 
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200. Leach, Newman         Standards Track             [Page 20] 
  1201.  
  1202.  
  1203.                          Digest SASL Mechanism          September, 1999 
  1204.  
  1205.  
  1206.  
  1207.  
  1208. [RFC 2047] Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part 
  1209.   Three: Message Header Extensions for Non-ASCII Text", RFC 2047, 
  1210.   University of Tennessee, November 1996.  
  1211.  
  1212. [RFC 2052] A. Gulbrandsen, P. Vixie, A DNS RR for specifying the 
  1213.   location of services (DNS SRV). October 1996. 
  1214.  
  1215.  [RFC 2060] Crispin, "Internet Message Access Protocol - Version 4rev1", 
  1216.   RFC 2060, University of Washington, December 1996. 
  1217.  
  1218.  [RFC 2104] H. Krawczyk, M. Bellare, R. Canetti, "HMAC: Keyed-Hashing 
  1219.   for  Message Authentication", RFC 2104, 02/05/1997 
  1220.  
  1221. [RFC2195] Klensin, J., et. al., "IMAP/POP AUTHorize Extension for Simple 
  1222.   Challenge/Response", RFC 2195, September, 1997. 
  1223.  
  1224. [RFC 2119] Bradner, S., "Key words for use in RFCs to Indicate 
  1225.   Requirement Levels," RFC 2119, Harvard University, March 1997. 
  1226.  
  1227. [USASCII] US-ASCII. Coded Character Set - 7-Bit American Standard Code 
  1228.   for Information Interchange. Standard ANSI X3.4-1986, ANSI, 1986.  
  1229.  
  1230.  
  1231. 6  Authors' Addresses 
  1232.  
  1233. Paul Leach 
  1234. Microsoft 
  1235. 1 Microsoft Way 
  1236. Redmond, WA  98052 
  1237. paulle@microsoft.com 
  1238.  
  1239. Chris Newman 
  1240. Innosoft International, Inc. 
  1241. 1050 Lakes Drive 
  1242. West Covina, CA 91790 USA 
  1243. chris.newman@innosoft.com 
  1244.  
  1245.  
  1246. 7  ABNF 
  1247.  
  1248. What follows is the definition of the notation as is used in the 
  1249. HTTP/1.1 specification (RFC 2616) and the HTTP authentication 
  1250. specification (RFC 2617); it is reproduced here for ease of reference. 
  1251. Since it is intended that a single Digest implementation can support 
  1252. both HTTP and SASL-based protocols, the same notation is used in both to 
  1253. facilitate comparison and prevention of unwanted differences. Since it 
  1254. is cut-and-paste from the HTTP specifications, not all productions may 
  1255.  
  1256.  
  1257.  
  1258.  
  1259. Leach, Newman         Standards Track             [Page 21] 
  1260.  
  1261.  
  1262.                          Digest SASL Mechanism          September, 1999 
  1263.  
  1264.  
  1265.  
  1266.  
  1267. be used in this specification. It is also not quite legal ABNF; again, 
  1268. the errors were copied from the HTTP specifications. 
  1269.  
  1270. 7.1   Augmented BNF  
  1271.  
  1272. All of the mechanisms specified in this document are described in both 
  1273. prose and an augmented Backus-Naur Form (BNF) similar to that used by 
  1274. RFC 822 [RFC 822]. Implementers will need to be familiar with the 
  1275. notation in order to understand this specification. 
  1276.  
  1277. The augmented BNF includes the following constructs: 
  1278.  
  1279. name = definition 
  1280.   The name of a rule is simply the name itself (without any enclosing 
  1281.   "<" and ">") and is separated from its definition by the equal "=" 
  1282.   character. White space is only significant in that indentation of 
  1283.   continuation lines is used to indicate a rule definition that spans 
  1284.   more than one line. Certain basic rules are in uppercase, such as SP, 
  1285.   LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle brackets are used within 
  1286.   definitions whenever their presence will facilitate discerning the 
  1287.   use of rule names. 
  1288.  
  1289. "literal" 
  1290.   Quotation marks surround literal text. Unless stated otherwise, the 
  1291.   text is case-insensitive. 
  1292.  
  1293. rule1 | rule2 
  1294.   Elements separated by a bar ("|") are alternatives, e.g., "yes | no" 
  1295.   will accept yes or no. 
  1296.  
  1297. (rule1 rule2) 
  1298.   Elements enclosed in parentheses are treated as a single element. 
  1299.   Thus, "(elem (foo | bar) elem)" allows the token sequences 
  1300.   "elem foo elem" and "elem bar elem". 
  1301.  
  1302. *rule 
  1303.   The character "*" preceding an element indicates repetition. The full 
  1304.   form is "<n>*<m>element" indicating at least <n> and at most <m> 
  1305.   occurrences of element. Default values are 0 and infinity so that 
  1306.   "*(element)" allows any number, including zero; "1*element" requires 
  1307.   at least one; and "1*2element" allows one or two. 
  1308.  
  1309. [rule] 
  1310.   Square brackets enclose optional elements; "[foo bar]" is equivalent 
  1311.   to "*1(foo bar)". 
  1312.  
  1313. N rule  
  1314.   Specific repetition: "<n>(element)" is equivalent to 
  1315.  
  1316.  
  1317.  
  1318. Leach, Newman         Standards Track             [Page 22] 
  1319.  
  1320.  
  1321.                          Digest SASL Mechanism          September, 1999 
  1322.  
  1323.  
  1324.  
  1325.  
  1326.   "<n>*<n>(element)"; that is, exactly <n> occurrences of (element). 
  1327.   Thus 2DIGIT is a 2-digit number, and 3ALPHA is a string of three 
  1328.   alphabetic characters. 
  1329.  
  1330. #rule 
  1331.   A construct "#" is defined, similar to "*", for defining lists of 
  1332.   elements. The full form is "<n>#<m>element" indicating at least <n> 
  1333.   and at most <m> elements, each separated by one or more commas (",") 
  1334.   and OPTIONAL linear white space (LWS). This makes the usual form of 
  1335.   lists very easy; a rule such as 
  1336.     ( *LWS element *( *LWS "," *LWS element ))   
  1337.   can be shown as  
  1338.     1#element  
  1339.   Wherever this construct is used, null elements are allowed, but do 
  1340.   not contribute to the count of elements present. That is, "(element), 
  1341.   , (element) " is permitted, but counts as only two elements. 
  1342.   Therefore, where at least one element is required, at least one non-
  1343.   null element MUST be present. Default values are 0 and infinity so 
  1344.   that "#element" allows any number, including zero; "1#element" 
  1345.   requires at least one; and "1#2element" allows one or two. 
  1346.  
  1347. ; comment 
  1348.   A semi-colon, set off some distance to the right of rule text, starts 
  1349.   a comment that continues to the end of line. This is a simple way of 
  1350.   including useful notes in parallel with the specifications. 
  1351.  
  1352.  
  1353.    implied *LWS  
  1354.    The grammar described by this specification is word-based. Except 
  1355.   where noted otherwise, linear white space (LWS) can be included 
  1356.   between any two adjacent words (token or quoted-string), and between 
  1357.   adjacent words and separators, without changing the interpretation of 
  1358.   a field. At least one delimiter (LWS and/or separators) MUST exist 
  1359.   between any two tokens (for the definition of "token" below), since 
  1360.   they would otherwise be interpreted as a single token. 
  1361.  
  1362.  
  1363. 7.2   Basic Rules  
  1364.  
  1365. The following rules are used throughout this specification to describe 
  1366. basic parsing constructs. The US-ASCII coded character set is defined by 
  1367. ANSI X3.4-1986 [USASCII]. 
  1368.  
  1369.        OCTET          = <any 8-bit sequence of data> 
  1370.        CHAR           = <any US-ASCII character (octets 0 - 127)> 
  1371.        UPALPHA        = <any US-ASCII uppercase letter "A".."Z"> 
  1372.        LOALPHA        = <any US-ASCII lowercase letter "a".."z"> 
  1373.        ALPHA          = UPALPHA | LOALPHA 
  1374.        DIGIT          = <any US-ASCII digit "0".."9"> 
  1375.  
  1376.  
  1377.  
  1378. Leach, Newman         Standards Track             [Page 23] 
  1379.  
  1380.  
  1381.                          Digest SASL Mechanism          September, 1999 
  1382.  
  1383.  
  1384.  
  1385.  
  1386.        CTL            = <any US-ASCII control character 
  1387.                         (octets 0 - 31) and DEL (127)> 
  1388.        CR             = <US-ASCII CR, carriage return (13)> 
  1389.        LF             = <US-ASCII LF, linefeed (10)> 
  1390.        SP             = <US-ASCII SP, space (32)> 
  1391.        HT             = <US-ASCII HT, horizontal-tab (9)> 
  1392.        <">            = <US-ASCII double-quote mark (34)> 
  1393.        CRLF           = CR LF 
  1394.  
  1395. All linear white space, including folding, has the same semantics as SP. 
  1396. A recipient MAY replace any linear white space with a single SP before 
  1397. interpreting the field value or forwarding the message downstream. 
  1398.  
  1399.        LWS            = [CRLF] 1*( SP | HT ) 
  1400.  
  1401. The TEXT rule is only used for descriptive field contents and values 
  1402. that are not intended to be interpreted by the message parser. Words of 
  1403. *TEXT MAY contain characters from character sets other than ISO-8859-1 
  1404. [ISO 8859] only when encoded according to the rules of RFC 2047 [RFC 
  1405. 2047]. 
  1406.  
  1407.        TEXT           = <any OCTET except CTLs, 
  1408.                         but including LWS> 
  1409.  
  1410. A CRLF is allowed in the definition of TEXT only as part of a header 
  1411. field continuation. It is expected that the folding LWS will be replaced 
  1412. with a single SP before interpretation of the TEXT value. 
  1413.  
  1414. Hexadecimal numeric characters are used in several protocol elements. 
  1415.  
  1416.        HEX            = "A" | "B" | "C" | "D" | "E" | "F" 
  1417.                       | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT 
  1418.  
  1419. Many HTTP/1.1 header field values consist of words separated by LWS or 
  1420. special characters. These special characters MUST be in a quoted string 
  1421. to be used within a parameter value. 
  1422.  
  1423.        token          = 1*<any CHAR except CTLs or separators> 
  1424.        separators     = "(" | ")" | "<" | ">" | "@" 
  1425.                       | "," | ";" | ":" | "\" | <"> 
  1426.                       | "/" | "[" | "]" | "?" | "=" 
  1427.                       | "{" | "}" | SP | HT 
  1428.  
  1429. A string of text is parsed as a single word if it is quoted using 
  1430. double-quote marks. 
  1431.  
  1432.       quoted-string  = ( <"> qdstr-val <"> ) 
  1433.       qdstr-val      = *( qdtext | quoted-pair ) 
  1434.       qdtext         = <any TEXT except <">> 
  1435.  
  1436.  
  1437.  
  1438.  
  1439. Leach, Newman         Standards Track             [Page 24] 
  1440.  
  1441.  
  1442.                          Digest SASL Mechanism          September, 1999 
  1443.  
  1444.  
  1445.  
  1446.  
  1447. Note that LWS is NOT implicit between the double-quote marks (<">) 
  1448. surrounding a qdstr-val and the qdstr-val; any LWS will be considered 
  1449. part of the qdstr-val.  This is also the case for quotation marks 
  1450. surrounding any other construct. 
  1451.  
  1452.  The backslash character ("\") MAY be used as a single-character quoting 
  1453. mechanism only within qdstr-val and comment constructs. 
  1454.  
  1455.        quoted-pair    = "\" CHAR 
  1456.  
  1457. The value of this construct is CHAR. Note that an effect of this rule is 
  1458. that backslash must be quoted. 
  1459.  
  1460.  
  1461. 8  Sample Code 
  1462.  
  1463. The sample implementation in [Digest] also applies to DIGEST-MD5. 
  1464.  
  1465. The following code implements the conversion from UTF-8 to 8859-1 if 
  1466. necessary. 
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500. Leach, Newman         Standards Track             [Page 25] 
  1501.  
  1502.  
  1503.                          Digest SASL Mechanism          September, 1999 
  1504.  
  1505.  
  1506.  
  1507.  
  1508.     /* if the string is entirely in the 8859-1 subset of UTF-8, then 
  1509.      * translate to 8859-1 prior to MD5 
  1510.      */ 
  1511.     void MD5_UTF8_8859_1(MD5_CTX *ctx, const unsigned char *base, 
  1512.         int len) 
  1513.     { 
  1514.         const unsigned char *scan, *end; 
  1515.         unsigned char cbuf; 
  1516.       
  1517.         end = base + len; 
  1518.         for (scan = base; scan < end; ++scan) { 
  1519.             if (*scan > 0xC3) break; /* abort if outside 8859-1 */ 
  1520.             if (*scan >= 0xC0 && *scan <= 0xC3) { 
  1521.                 if (++scan == end || *scan < 0x80 || *scan > 0xBF) 
  1522.                     break; 
  1523.             } 
  1524.         } 
  1525.         /* if we found a character outside 8859-1, don't alter string 
  1526.          */ 
  1527.         if (scan < end) { 
  1528.             MD5Update(ctx, base, len); 
  1529.             return; 
  1530.         } 
  1531.       
  1532.         /* convert to 8859-1 prior to applying hash 
  1533.          */ 
  1534.         do { 
  1535.             for (scan = base; scan < end && *scan < 0xC0; ++scan) 
  1536.                 ; 
  1537.             if (scan != base) MD5Update(ctx, base, scan - base); 
  1538.             if (scan + 1 >= end) break; 
  1539.             cbuf = ((scan[0] & 0x3) << 6) | (scan[1] & 0x3f); 
  1540.             MD5Update(ctx, &cbuf, 1); 
  1541.             base = scan + 2; 
  1542.         } while (base < end); 
  1543.     } 
  1544.      
  1545.  
  1546. 9  Full Copyright Statement 
  1547.  
  1548. Copyright (C) The Internet Society (1998). All Rights Reserved. 
  1549.  
  1550. This document and translations of it may be copied and furnished to 
  1551. others, and derivative works that comment on or otherwise explain it or 
  1552. assist in its implementation may be prepared, copied, published and 
  1553. distributed, in whole or in part, without restriction of any kind, 
  1554. provided that the above copyright notice and this paragraph are included 
  1555. on all such copies and derivative works. However, this document itself 
  1556. may not be modified in any way, such as by removing the copyright notice 
  1557. or references to the Internet Society or other Internet organizations, 
  1558.  
  1559.  
  1560.  
  1561. Leach, Newman         Standards Track             [Page 26] 
  1562.  
  1563.  
  1564.                          Digest SASL Mechanism          September, 1999 
  1565.  
  1566.  
  1567.  
  1568.  
  1569. except as needed for the purpose of developing Internet standards in 
  1570. which case the procedures for copyrights defined in the Internet 
  1571. Standards process must be followed, or as required to translate it into 
  1572. languages other than English. 
  1573.  
  1574. The limited permissions granted above are perpetual and will not be 
  1575. revoked by the Internet Society or its successors or assigns. 
  1576.  
  1577. This document and the information contained herein is provided on an "AS 
  1578. IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK 
  1579. FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  1580. LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT 
  1581. INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR 
  1582. FITNESS FOR A PARTICULAR PURPOSE.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622. Leach, Newman         Standards Track             [Page 27]